package com.yy.xshell.process;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author wxy
 * @version 1.0
 * @date 2024/8/20 15:36
 */
public abstract class Handler<T> {

    protected Logger log = LoggerFactory.getLogger(Handler.class);

    public Handler<T> next;

    public T invoke(T str){
        if(accept(str)){
            T t = handler(str);
            return next != null ? next.invoke(t) : t;
        }
        if(next != null){
            return next.invoke(str);
        }
        return str;
    }

    public abstract T handler(T command);

    public abstract boolean accept(T command);

}
